
* THIS PROGRAM EXTRACTS LOAN HISTORY DATA NEEDED FOR THE PROJECT;

libname lib1 "ABSNet data directory"; *This is the directory where the original ABSNet loan history data is saved;

data temp; set lib1.loanhistory(keep= ABSNetLoanFK
HistLoanStatus
HistStartDate
HistEndDate
BankruptcyDate
ForeclosureDate
ReoDate
LewtanModifiedDate
PrepaymentDate
LiquidationDate
RepurchaseDate); * This is the original ABSNet loan history dataset;
endyear=year(datepart(HistEndDate));
if endyear ge 2007 and endyear le 2016;
startyear=year(datepart(HistStartDate));
if startyear ge 2001 and startyear le 2007;
if HistLoanStatus ne "";
run;

libname lib2 "destination directory"; * SELECT THE DESTINATION FOLDER;

data lib2.loanhistory(drop= HistStartDate HistEndDate BankruptcyDate ForeclosureDate ReoDate LewtanModifiedDate PrepaymentDate 
LiquidationDate RepurchaseDate rename= (_HistStartDate=HistStartDate _HistEndDate=HistEndDate _BankruptcyDate=BankruptcyDate _ForeclosureDate=ForeclosureDate _ReoDate=ReoDate 
_LewtanModifiedDate=LewtanModifiedDate _PrepaymentDate=PrepaymentDate _LiquidationDate=LiquidationDate _RepurchaseDate=RepurchaseDate)); 
set temp;
_HistStartDate = datepart(HistStartDate);
_HistEndDate = datepart(HistEndDate);
_BankruptcyDate = datepart(BankruptcyDate);
_ForeclosureDate = datepart(ForeclosureDate);
_ReoDate = datepart(ReoDate);
_LewtanModifiedDate = datepart(LewtanModifiedDate);
_PrepaymentDate = datepart(PrepaymentDate);
_LiquidationDate = datepart(LiquidationDate);
_RepurchaseDate = datepart(RepurchaseDate);
run;

